var InterValObj;//变量控制时间
var count= 60;//间隔函数，1秒执行
var curCount;//当前剩余秒数
//发送验证码
function sendMessage(){
    curCount=count;
    document.getElementById("yzm").setAttribute("disabled","true");
    document.getElementById("yzm").value=curCount + "秒后重获";
    InterValObj=window.setInterval(SetRemainTime,1000);
}
function SetRemainTime() {
if (curCount==0){
    window.clearInterval(InterValObj);
    document.getElementById("yzm").removeAttribute("disabled");
    document.getElementById("yzm").value="重获验证码";
}else {
    curCount--;
    document.getElementById("yzm").value=curCount + "秒后重获";
}
}
function foLogin() {
    //定义变量
    var u_name = document.getElementById('name');
    var uError = document.getElementById('error_box');
    var uError2 = document.getElementById('error_box2');
    var uError3 = document.getElementById('error_box3');
    var uError4 = document.getElementById('error_box4');
    //var uError5 = document.getElementById('error_box5');
    var u_pwd = document.getElementById('upwd');
    var u_pwd2 = document.getElementById('upwd2');
    var u_email = document.getElementById('email');
    var inputCode = document.getElementById('u_code');
    var isError = true;
    uError.innerHTML = "";
    uError2.innerHTML = "";
    uError3.innerHTML = "";
    uError4.innerHTML = "";
  //  uError5.innerHTML = "";
    //对用户名进行判断

    if (u_name.value.length < 3 || u_name.value.length > 20 || u_name.value == '') {
        uError.innerHTML = '请输入3-20位的用户名';
        isError = false;
        return;
    } else if (u_name.value.charCodeAt(0) >= 48 && (u_name.value.charCodeAt(0) <= 57)) {
        uError.innerHTML = "用户名首位不能为数字";
        return;
    }
    //对用户输入的密码进行判断

    if (u_pwd.value.length < 6 || u_pwd.value.length > 1000 || u_pwd.value == '') {
        uError2.innerHTML = "请输入6-1000位的密码";
        isError = false;
        return;
    } else if (u_pwd.value != u_pwd2.value) {
        uError3.innerHTML = "两次密码不一致，请重新输入！";
        isError = false;
        return;
        //邮箱判断
    }
    if (u_email.value == '') {
        uError4.innerHTML = "请输入用户邮箱";
        isoError = false;
        return;
    }
   /* //验证码判断
    if (inputCode.value.toUpperCase() != code || inputCode.value == '') {
        uError5.innerHTML = "验证码错误，请正确输入验证码！";
        isError = false;
        return;

    } else {
        uError5.innerHTML = "";
        setTimeout(function () { window.open("../html/enter.html") }, 1000);
        alert("登录完成！点击跳转到登录页面...");
        isError = true;
        return;
    
    }*/
  
}
//=========获取表单数据=============
function getFormData() {
    var formData = {};
    var salt ="springbootdemo";
    var newPassword = $.md5($("#upwd").val()+ salt); // 前端密码加密
    console.log("md5 new pwd:" + newPassword)

    $("#upwd").val(newPassword);
    $("#upwd2").val(newPassword);

    var data = $('#form').serialize();

     $.post(
        "../customer",
        data,
        function (result){
            console.log(result)
             if(result.code == 200){
                location.href="login.jsp"
            } else{
                 $(".error_box4").text("regist failed,please regist again!")
             }

        },
        "json");
}
